package com.ssm.example.controller;

import com.alibaba.druid.support.json.JSONUtils;
import com.ssm.example.JwtToken;
import com.ssm.example.entity.TokenJWT;
import com.ssm.example.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssm.example.entity.UserEntity;
import com.ssm.example.service.UserService;

@Controller
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/getUser")
	@ResponseBody
	public UserEntity getUser( ) {

		UserEntity user = userService.getUser();
		return user;
	}

	@RequestMapping("/login")
	@ResponseBody
	//json  post请求 需要在参数上添加requestbody
	public TokenJWT login(@RequestBody User data) throws Exception {

    if(data.getEmail().equals("1@qq.com")&&data.getPassword().equals("1111")){
			String Token=	JwtToken.createToken(data.getEmail());
			TokenJWT token1 =new TokenJWT();
			token1.setToken(Token);


			return  token1;
		}
       return  null;
//		UserEntity user = userService.getUser();
//
//		String a= JSONUtils.toJSONString(user);
//		return  a;


	}
	
	

}
